package com.zr.system.service.impl;

import com.zr.common.utils.DateUtils;
import com.zr.common.utils.SecurityUtils;
import com.zr.common.core.domain.entity.SysOrganization;
import com.zr.system.mapper.SysOrganizationMapper;
import com.zr.system.service.ISysOrganizationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 组织Service业务层处理
 * 
 * @author why
 * @date 2022-10-24
 */
@Service
public class SysOrganizationServiceImpl implements ISysOrganizationService 
{
    @Resource
    private SysOrganizationMapper sysOrganizationMapper;

    /**
     * 查询组织
     * 
     * @param id 组织主键
     * @return 组织
     */
    @Override
    public SysOrganization selectSysOrganizationById(Long id)
    {
        return sysOrganizationMapper.selectSysOrganizationById(id);
    }

    /**
     * 查询组织列表
     * 
     * @param sysOrganization 组织
     * @return 组织
     */
    @Override
    public List<SysOrganization> selectSysOrganizationList(SysOrganization sysOrganization)
    {
        return sysOrganizationMapper.selectSysOrganizationList(sysOrganization);
    }

    /**
     * 新增组织
     * 
     * @param sysOrganization 组织
     * @return 结果
     */
    @Override
    public int insertSysOrganization(SysOrganization sysOrganization)
    {
        sysOrganization.setCreateTime(DateUtils.getNowDate());
        sysOrganization.setCreateId(SecurityUtils.getUsername());
        return sysOrganizationMapper.insertSysOrganization(sysOrganization);
    }

    /**
     * 修改组织
     * 
     * @param sysOrganization 组织
     * @return 结果
     */
    @Override
    public int updateSysOrganization(SysOrganization sysOrganization)
    {
        sysOrganization.setUpdateTime(DateUtils.getNowDate());
        sysOrganization.setUpdateId(SecurityUtils.getUsername());

        return sysOrganizationMapper.updateSysOrganization(sysOrganization);
    }

    /**
     * 批量删除组织
     * 
     * @param ids 需要删除的组织主键
     * @return 结果
     */
    @Override
    public int deleteSysOrganizationByIds(Long[] ids)
    {
        return sysOrganizationMapper.deleteSysOrganizationByIds(ids);
    }

    /**
     * 删除组织信息
     * 
     * @param id 组织主键
     * @return 结果
     */
    @Override
    public int deleteSysOrganizationById(Long id)
    {
        return sysOrganizationMapper.deleteSysOrganizationById(id);
    }

/**
     * 查询执行任务小组列表
     *
     * @param type 任务类型
     * @param organizationId 当前登录人所在组织
     * @return 组织集合
     */
    @Override
    public List<SysOrganization> selectTaskGroupList(String type, Long organizationId) {
        return sysOrganizationMapper.selectTaskGroupList(type,organizationId);
    }
}
